<?php

namespace Common\Model;

/**
 * DealerLoginModel.class.php实例模型
 * 
 * @author zhangzhen
 * @date 2017-1-4
 */
class DealerLoginModel extends BaseModel {

    protected $trueTableName = 'tb_dealer_login';

    /**
     * 手机号返回用户数据
     * @modify zhangzhen 2017-01-04
     * @param string $mobile 手机号
     * @return type
     */
    public function getInfoByMobile($mobile, $areacode = '86') {
        return $this->where(array('mobile' => $mobile,'areacode' => $areacode))->find();
    }

    /**
     * 添加用户
     * @modify zhangzhen 2017-01-04
     * @param string $mobile 手机号
     * @param string $password  密码
     * @param string $name  用户名称
     * @return type
     */
    public function addInfo($mobile, $password, $name, $enddate, $areacode = '86') {
        $options = array(
            'mobile' => $mobile,
            'password' => $password,
            'name' => $name,
            'enddate' => $enddate,
            'areacode' => $areacode,
        );
        return $this->add($options);
    }

    /**
     * 修改经销商的到期时间
     * @modify zhangzhen 2017-1-11
     * @param string $dealerId 经销商Id
     * @return type
     */
    public function saveInfo($dealerId, $data) {
        $options = array(
            'id' => $dealerId,
        );
        return $this->where($options)->save($data);
    }

    /**
     * 获取信息
     * @modify zhangzhen 2017-01-04 创建
     * @param  mixin   $dealerId        管理员id(s)
     * @return array              信息数组
     */
    public function getInfo($dealerId) {
        $option = array();

        if (is_array($dealerId)) {
            $dealerId = implode(',', $dealerId);
        }
        if (strpos($dealerId, ',') !== false) {
            $option['id'] = array('in', $dealerId);
            $data = $this->where($option)->select();
        } else {
            $option['id'] = $dealerId;
            $data = $this->where($option)->find();
        }

        return empty($data) ? array() : $data;
    }
}
